import React, { Component } from 'react'
import './index.css'
export default class header extends Component {


    handleKeyUp = (event)=>{
        const {keyCode,target} = event
        //判断是否按下回车按键
        if(keyCode !== 13) return
        //输入不能为空
        if(target.value.trim() === ''){
            alert('输入不能为空')
            return
        }
        const todoObj = {id:Math.random().toString(36).substr(2),name:target.value,done:false}
        this.props.addtodo(todoObj)
        //清空输入 
        target.value = ''
    }
    render() {

        return (
            <div className="todo-header">
            <input onKeyUp={this.handleKeyUp} type="text" placeholder="请输入你的任务名称，按回车键确认" />
            </div>
        )
    }
}
